package com.jun.seckill_by_jun.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

@Service
public class RedisPool {
    @Autowired
    private RedisConfig redisConfig;

    @Bean
    public JedisPool jedisPoolFactory(){
        JedisPoolConfig jpc = new JedisPoolConfig();
        jpc.setMaxIdle(redisConfig.getPoolMaxIdle());
        jpc.setMaxTotal(redisConfig.getPoolMaxTotal());
        jpc.setMaxWaitMillis(redisConfig.getPollMaxWait()*1000);
        JedisPool jp = new JedisPool(jpc,redisConfig.getHost(),redisConfig.getPort(),
                redisConfig.getTimeout()*1000,redisConfig.getPassword(),0);
        return jp;
    }
}
